import 'package:flutter/material.dart';
import 'package:hook_rent/pages/home/tab_index/index.dart';
import 'package:hook_rent/pages/home/tab_info/index.dart';
import 'package:hook_rent/pages/home/tab_search/index.dart';
import 'package:hook_rent/widgets/page_content.dart';

// tabbar 页面列表
List<Widget> tabViewList = [
  const TabIndex(title: "首页"),
  const TabSearch(),
  const TabInfo(),
  const PageContent(name: "我的"),
];
// tabbar 标签列表
List<BottomNavigationBarItem> tabList = [
  const BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
  const BottomNavigationBarItem(icon: Icon(Icons.search), label: "搜索"),
  const BottomNavigationBarItem(icon: Icon(Icons.rss_feed), label: "资讯"),
  const BottomNavigationBarItem(icon: Icon(Icons.person), label: "我的"),
];

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _selectedIndex = 0;
  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: tabViewList[_selectedIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: tabList,
        currentIndex: _selectedIndex,
        type: BottomNavigationBarType.fixed,
        onTap: _onItemTapped,
        selectedItemColor: Colors.blue,
      ),
    );
  }
}
